package com.njbw.tool;

import java.text.SimpleDateFormat;

public class SimpleDateFormatUtil {

    // 可以用 ThreadLocal 来规避 SimpleDateFormat 的线程不安全
    private static final ThreadLocal<SimpleDateFormat> THREAD_LOCAL = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

    public static SimpleDateFormat getTime() {
        SimpleDateFormat simpleDateFormat = THREAD_LOCAL.get();
        if (null == simpleDateFormat) {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
        return simpleDateFormat;
    }
}
